<template>
  <div class="app-container">
    <!-- 搜索栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="充电桩名称" prop="pileName">
        <el-input v-model="queryParams.pileName" placeholder="请输入充电桩名称" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="充电桩编码" prop="deviceId">
        <el-input v-model="queryParams.deviceId" placeholder="请输入充电桩编码" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="设备状态" prop="deviceState">
        <el-select v-model="queryParams.deviceState" placeholder="请选择设备状态">
          <el-option v-for="dict in dict.type.iot_device_state" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="终端类型" prop="terminalType">
        <el-select v-model="queryParams.terminalType" placeholder="请选择终端类型">
          <el-option v-for="dict in dict.type.current_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-row>
      <el-card shadow="hover" v-for="item in lists" :key="item.id">
        <el-row class="infoTop">
          <div>电桩编码：{{item.deviceId}}</div>
          <div>额定功率：{{item.ratedPower}}</div>
          <div>设置功率：{{item.maxPower}}</div>
          <div>实时功率：{{item.realPower}}</div>
          <div style="display: flex;">
            <template>
              设备状态：<dict-tag :options="dict.type.iot_device_state" :value="item.deviceState" />
            </template>
          </div>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-descriptions :column="column">
              <el-descriptions-item label="电桩名称">{{item.pileName}}</el-descriptions-item>
              <el-descriptions-item label="归属场站">{{item.chargeStationName}}</el-descriptions-item>
              <el-descriptions-item label="启用状态">{{item.status===1?'启动':'未启动'}}</el-descriptions-item>
              <el-descriptions-item label="设备厂商">{{item.producer}}</el-descriptions-item>
              <el-descriptions-item label="终端类型">
                <template>
                  <dict-tag :options="dict.type.current_type" :value="item.terminalType" />
                </template>
              </el-descriptions-item>
              <el-descriptions-item label="网络链接类型">
                <template>
                  <dict-tag :options="dict.type.network_link_type" :value="item.networkLinkType" />
                </template>
              </el-descriptions-item>
              <el-descriptions-item label="固件版本">{{item.procedureVersion}}</el-descriptions-item>
              <el-descriptions-item label="出厂日期">{{item.factoryDate}}</el-descriptions-item>
            </el-descriptions>
          </el-col>
          <el-col :span="16">
            <el-table :data="item.chargePortList" stripe style="width: 100%" v-loading="loading">
              <el-table-column prop="portName" label="终端名称" align="center"></el-table-column>
              <el-table-column prop="id" label="终端编码" align="center"></el-table-column>
              <el-table-column prop="serviceStatus" label="工作状态" align="center">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.use_state" :value="scope.row.serviceStatus" />
                </template>
              </el-table-column>
              <el-table-column prop="realPower" label="实时功率" align="center"></el-table-column>
              <el-table-column prop="voltage" label="电压（V）" align="center"></el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-card>
    </el-row>
  </div>
</template>

<script>
import { listRealDetails } from '@/api/smart/trendsDispatch/real'
export default {
  name: 'realPowerInfo',
  dicts: ['use_state', 'current_type', 'network_link_type','iot_device_state'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 查询参数
      queryParams: {
        stationId: null, //场站id
        pileName: null, //充电桩名称
        deviceId: null, //充电桩编码
        serviceStatus: null, //在线状态
        terminalType: null //终端类型
      },
      //展示个数
      column: 2,
      // 列表项
      lists: []
    }
  },
  created() {
    this.$nextTick(() => {
      this.queryParams.stationId = this.$route.query.stationId
      this.handleQuery()
    })
  },
  methods: {
    /** 查询列表 */
    handleQuery() {
      this.loading = true
      listRealDetails(this.queryParams).then(res => {
        if (res.code === 200) {
          this.lists = res.rows
        }
        this.loading = false
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
<style lang="scss" scoped>
.infoTop {
  display: flex;
  margin-bottom: 2vh;
  > div {
    font-size: 14px;
    color: #333;
    margin-right: 4%;
  }
}
</style>
